﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Generator.Tools
{
    public partial class SQLConvert : Form
    {
        public SQLConvert()
        {
            InitializeComponent();
        }


        StringBuilder sb_param = new StringBuilder();
        private void button1_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            sb_param.Clear();

            //sb.AppendLine("StringBuilder sql = new StringBuilder();");
            foreach (var line in richTextBox1.Lines)
            {
                findParams(line);
                sb.AppendLine("sql.Append(\"" + line + " \");");
            }

            richTextBox2.Text = sb_param.ToString() + sb.ToString();
        }

        private void findParams(string line)
        {
            string pattern = @"@\w+";
            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(pattern);
            System.Text.RegularExpressions.MatchCollection matchs = regex.Matches(line);
            if (matchs.Count == 0)
                return;

            string[] res = new string[matchs.Count];
            for (int i = 0; i < matchs.Count; i++)
            {
                sb_param.AppendLine("/// " + matchs[i].Value);
            }

            

        }
    }
}
